﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;

namespace Framework.Network
{

    public class NetworkManager : FrameworkComponent
    {
        private Dictionary<string,INetworkChannel> m_channels=new Dictionary<string,INetworkChannel>();

        private void Start()
        {
          
        }

        public INetworkChannel CreatDefaultChannel(string name)
        {
            var packetHelper = new DefaultNetworkChannelPacketHelper();
            return CreatChannel(name, packetHelper);
        }
        public INetworkChannel GetChannel(string name)
        {
            if (m_channels.ContainsKey(name))
            {
                return m_channels[name];
            }

            return null;
        }
        public INetworkChannel CreatChannel(string name,INetworkChannelHelper packetHelper)
        {
            var channel=new NetworkChannel(name,packetHelper);
            m_channels.Add(name,channel);
            return channel;
        }

        public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            // throw new System.NotImplementedException();
            foreach (var channel in m_channels)
            {
                channel.Value.OnUpdate(elapseSeconds,realElapseSeconds);
            }
        }

        public override void Shutdown()
        {
            foreach (var channel in m_channels)
            {
                channel.Value.ShutDown();
            }
        }
    }

}